package com.chenyongjing.design.pattern.composite.general.safe;

import java.util.ArrayList;
import java.util.List;

public class Composite extends Component {
    private List<Component> mComponent;

    public Composite(String name) {
        super(name);
        this.mComponent = new ArrayList<Component>();
    }

    @Override
    public String opertion() {
        StringBuilder builder = new StringBuilder(this.name);
        for(Component component :this.mComponent){
            builder.append("\n");
            builder.append(component.opertion());
        }
        return builder.toString();
    }

    public boolean addChild(com.chenyongjing.design.pattern.composite.general.transparent.Component component){
        throw new UnsupportedOperationException("addChild not supported!");
    }

    public boolean removeChild(com.chenyongjing.design.pattern.composite.general.transparent.Component component){
        throw new UnsupportedOperationException("removeChild not supported!");
    }

    public com.chenyongjing.design.pattern.composite.general.transparent.Component getChild(int index){
        throw new UnsupportedOperationException("getChild not supported!");
    }
}
